package com.sangeng.controller;

import com.sangeng.annotation.SystemLog;
import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.entity.Menu;
import com.sangeng.domain.vo.RoleMenuVo;
import com.sangeng.service.MenuService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: MenuController
 * Package: com.sangeng.controller
 * Description:
 *
 * @Author hjh
 * @Create 2024/8/25 18:54
 * @Version 1.0
 */
@RestController
@RequestMapping("system/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @SystemLog(businessName = "展示菜单列表接口")
    @GetMapping("/list")
    public ResponseResult getList(String status,String menuName){
       return   menuService.getList(status,menuName);
    }

    @SystemLog(businessName = "新增菜单接口")
    @PostMapping()
    public ResponseResult addMenu(@RequestBody Menu menu){
        return menuService.addMenu(menu);
    }

    @SystemLog(businessName = "根据id查询菜单接口")
    @GetMapping("/{id}")
    public ResponseResult updateMenu(@PathVariable Long id){
        Menu menu = menuService.getById(id);
        return ResponseResult.okResult(menu);
    }

    @SystemLog(businessName = "更新菜单")
    @PutMapping
    public ResponseResult updateMenu(@RequestBody Menu menu){
       return menuService.updateMenu(menu);
    }

    @SystemLog(businessName = "删除菜单")
    @DeleteMapping("/{menuId}")
    public ResponseResult deleteByMenuId(@PathVariable Long menuId){
        return menuService.deleteByMenuId(menuId);
    }

    @SystemLog(businessName = "获取菜单树接口")
    @GetMapping("/treeselect")
    public ResponseResult treeSelect(){
        List<RoleMenuVo> menuVos=menuService.treeSelect();
       return ResponseResult.okResult(menuVos);
    }

    @SystemLog(businessName = "加载对应角色菜单列表树接口")
    @GetMapping("roleMenuTreeselect/{id}")
    public ResponseResult roleMenuTreeSelect(@PathVariable Long id){
       return menuService.roleMenuTreeSelect(id);
    }
}
